package com.zpkj.portal.conf;

import com.zpkj.portal.interceptor.SecurityInterceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.zpkj.portal.interceptor.IpInterceptor;
import com.zpkj.portal.interceptor.LogInterceptor;

/**
 * @author Kelvin
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// TODO Auto-generated method stub
		super.addInterceptors(registry);
		registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**").excludePathPatterns("/static/**",
				"/**/*.jsp");

		// --安全校验(v3.1临时安全认证 2017-9-1 author：chenk)
		registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/user/getUserInfo", "/user/logout")
				.excludePathPatterns("/help/helpList");

		registry.addInterceptor(new IpInterceptor()).addPathPatterns("/**");

	}

//    @Override
//    public void configureViewResolvers(ViewResolverRegistry registry) {
//        registry.enableContentNegotiation(new MappingJackson2JsonView());
//        registry.freeMarker().cache(false);
//    }
//
//    @Bean
//    public FreeMarkerConfigurer freeMarkerConfigurer() {
//        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
//        configurer.setTemplateLoaderPath("/WEB-INF/");
//        return configurer;
//    }
}
